package com.goudan.rabbitmq.config;

import com.goudan.rabbitmq.constant.QueueDefinition;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.FanoutExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName FanoutModeConfig
 * @Description 扇出模式配置
 * @Author lizejiao
 * @Date 2021/9/9 2:47 下午
 **/
@Slf4j
@Configuration
public class FanoutModeConfig {

    /**
     * 2.定义队列
     */
    @Bean
    public Queue fanoutQueue() {
        return new Queue(QueueDefinition.LGD_FANOUT_QUEUE);
    }

    /**
     * 2.定义交换机
     */
    @Bean
    FanoutExchange fanoutExchange() {
        return new FanoutExchange(QueueDefinition.LGD_FANOUT_EXCHANGE);
    }

    /**
     * 3.队列与交换机绑定邮件队列
     */
    @Bean
    public Binding bindingExchangeEmail(Queue fanoutQueue, FanoutExchange fanoutExchange) {
        return BindingBuilder.bind(fanoutQueue).to(fanoutExchange);
    }

}
